import 'package:eplorex/pages/message/state/inherited_chat_theme.dart';
import 'package:eplorex/pages/message/state/inherited_l10n.dart';
import 'package:flutter/material.dart';


class VoiceButton extends StatelessWidget {

  const VoiceButton({
    super.key,
    this.isLoading = false,
    this.onPressed,
    this.padding = EdgeInsets.zero,
  });

  /// Show a loading indicator instead of the button.
  final bool isLoading;

  /// Callback for attachment button tap event.
  final VoidCallback? onPressed;

  /// Padding around the button.
  final EdgeInsets padding;


  @override
  Widget build(BuildContext context) {
    return Container(
      margin: InheritedChatTheme.of(context).theme.attachmentButtonMargin ??
          const EdgeInsetsDirectional.fromSTEB(
            8,
            0,
            0,
            0,
          ),
      child: IconButton(
        constraints: const BoxConstraints(
          minHeight: 24,
          minWidth: 24,
        ),
        icon: isLoading
            ? SizedBox(
          height: 20,
          width: 20,
          child: CircularProgressIndicator(
            backgroundColor: Colors.transparent,
            strokeWidth: 1.5,
            valueColor: AlwaysStoppedAnimation<Color>(
              InheritedChatTheme.of(context).theme.inputTextColor,
            ),
          ),
        )
            : InheritedChatTheme.of(context).theme.attachmentButtonIcon ??
            Image.asset(
              width: 40,
              'assets/voice.png',
              color: InheritedChatTheme.of(context).theme.inputTextColor,
            ),
        onPressed: isLoading ? null : onPressed,
        padding: padding,
        splashRadius: 24,
        tooltip:
        InheritedL10n.of(context).l10n.attachmentButtonAccessibilityLabel,
      ),
    );
  }
}
